package ar.com.ford.it.fullEconomics.persistence.dao.query;

import oracle.toplink.expressions.Expression;
import oracle.toplink.expressions.ExpressionBuilder;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesc05Itemcatgry;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesc06Item;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesg01Plant;
import com.ford.it.persistence.impl.toplink.CustomExpressionFactory;

public class ItemsApprovedFindQuery implements CustomExpressionFactory {

    public Expression createExpression(ExpressionBuilder builder, Object[] parameters) {
        Expression exp = null;
        Teesc06Item item = (Teesc06Item) parameters[0];
        Teesg01Plant plant = item.getEesc06PlantCodeC();
        Teesc05Itemcatgry itemCategory = item.getTeesc05Itemcatgry();
        
        exp = builder.get("eesc06PlantCodeC").equal(plant);
        if (itemCategory != null) {
            exp = exp.and(builder.get("teesc05Itemcatgry").equal(itemCategory));
        }
        exp = exp.and(builder.get("eesc06ItemApprovalUserC").notNull());
        
        return exp;
    }

}
